var WFWidgetPackageManager = new Class ({
	myJSON:null,
    checkWidget: function(){
        return this.check("check", "widget");
    },
    checkConfigureWidgetAndWidgetComponent: function(){
        return this.check("check", "configure_widget_and_widget_component");
    },
    check: function(act, update_type){
        this.myJSON = new WFRequest.JSON({
            url:homeBase+"inc/widget_package_manager.php?"+ AddUrlParam(),
            method: 'post',
            async: false,
            timeout: ajaxTimeoutValue,
            data:JSON.encode({ "act":act,"update_type":update_type }),
            urlEncoded: false,
            headers: {"Content-type": "application/json"}
        });
        this.myJSON.send();
        if(this.myJSON.response.json.errcode==0){
            return this.myJSON.response.json.result['Status']==0;
        }else{
            return false;
        }
    },
    updateWidget:function(completeEvent){
        this.update(completeEvent, "update", "widget", null);
    },
    updateConfigureWidgetOrWidgetComponent:function(completeEvent, update_type, product_id){
        this.update(completeEvent, "update", update_type, product_id);
    },
    update:function(completeEvent, act, update_type, product_id){
        this.myJSON = new WFRequest.JSON({
            url:homeBase+"inc/widget_package_manager.php?"+ AddUrlParam(),
            timeout: ajaxTimeoutValue_update_widgetPool,
            async: true,
            data:JSON.encode({ "act":act, "update_type": update_type, "product_id": product_id }),
            urlEncoded: false,
            headers: {"Content-type": "application/json"},
            onFailure: function(reqObj){
                if (reqObj.isTimeout) {
                    this.myJSON.response = null;
                    // fire complete event
                    if (completeEvent) {
                        completeEvent.bind(this)(this.myJSON);
                    }
                    return;
                }

                // fire complete event
                if (completeEvent) {
                    completeEvent.bind(this)(this.myJSON);
                }
            }.bind(this),
            onSuccess: function(reqObj) {
                // fire complete event
                if (completeEvent) {
                    completeEvent.bind(this)(this.myJSON);
                }
            }.bind(this)
        });
        this.myJSON.send();
    },
    getConfigureWidgetAndWidgetComponent: function(){
        this.myJSON = new WFRequest.JSON({
            url:homeBase+"inc/widget_package_manager.php?"+ AddUrlParam(),
            method: 'post',
            async: false,
            timeout: ajaxTimeoutValue,
            data:JSON.encode({ "act":"get_configure_widget_and_wiget_component", "isNewWcuUpdate": (wpm_check_new_scm ? wpm_check_new_scm["is_new_wcu_update"] : false) }),
            urlEncoded: false,
            headers: {"Content-type": "application/json"}
        });
        this.myJSON.send();
        if(this.myJSON.response.json.errcode==0){
            return this.myJSON.response.json.result;
        }
    }
});
 


